<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\api\controller\learn\book;

use app\api\controller\Controller;
use app\api\model\learn\book\Comment as CommentModel;
use app\api\model\learn\book\Note as NoteModel;
use think\facade\Db;
use think\response\Json;

/**
 * 笔记
 * Class Category
 * @package app\api\controller\article
 */
class Note extends Controller {
	/**
	 * 文章分类列表
	 * @return Json
	 * @throws \think\db\exception\DataNotFoundException
	 * @throws \think\db\exception\DbException
	 * @throws \think\db\exception\ModelNotFoundException
	 */
	public function list(): Json {

		$model = new NoteModel;
		$list = $model->getList($this->request->param());
		return $this->renderSuccess(compact('list'));
	}
 public function remove(int $noteId): Json
    {
        $model = NoteModel::detail($noteId);
        if ($model->remove()) {
            return $this->renderSuccess([], '删除成功');
        }
        return $this->renderError($model->getError() ?: '删除失败');
    }
	//评论,笔记
	public function save() {

		$model = new CommentModel;

		if ($this->postForm()['is_comment'] == 1) {
			$model->increased($this->postForm());
		}
		if ($this->postForm()['can_comment']) {
			$notemodel = new NoteModel;
			$notemodel->add($this->postForm());
		} else {
			$notemodel = NoteModel::detail($this->postForm()['id']);
			$notemodel->edit($this->postForm());
		}

		return $this->renderSuccess();
	}

}